<template>
  <div class="userInfo">
    <p>个人信息</p>
    <div class="info">
      <img src="https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3863823676,2961251940&fm=58" alt="">
      <section>
        <p>{{userName}}，欢迎您！<el-tag type="success">在岗</el-tag></p>
        <p>所属部门：{{section}}</p>
        <p>所属学科：{{course}}</p>
        <p>所教班级：{{className}}</p>
        <el-button type="warning" size="small" style="width: 240px; margin: 26px 0;" @click="dialogInfo = true">详细信息</el-button>
      </section>
    </div>
    <!-- 详细信息 -->
    <el-dialog
      title="详细信息"
      :visible.sync="dialogInfo"
      width="30%"
      :before-close="handleClose">
<!--      <span>详细信息</span>-->
      <el-table
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column
          prop="date"
          label="日期"
          width="180">
        </el-table-column>
        <el-table-column
          prop="name"
          label="姓名"
          width="180">
        </el-table-column>
        <el-table-column
          prop="address"
          label="地址">
        </el-table-column>
        <el-table-column label="姓名" >
          <template slot-scope="scope">
            <el-input size="small" v-model="scope.row.name" placeholder="请输入名字" @change="handleEdit(scope.$index, scope.row)"></el-input> <span>123</span>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogInfo = false">取 消</el-button>
        <el-button type="primary" @click="dialogInfo = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'UserInfo',
  data () {
    return {
      dialogInfo: false, // 对话框状态
      userName: '', // 用户名
      section: '', // 部门
      course: '', // 学科
      className: '', // 班级
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }]
    }
  },
  methods: {
    /**
     * 获取用户信息
     */
    getUserInfo () {
      let paramUserInfo = {
        userId: this.$storage.get('userId')
      };
      this.$api.getUserInfo(paramUserInfo).then(res => {
        this.userName = res.userName;
        this.section = res.section;
        this.course = res.course;
        this.className = res.className;
      })
    },
    /**
     * 关闭前的回调，会暂停 Dialog 的关闭
     * @param {function}(done)，done 用于关闭 Dialog
     */
    handleClose (done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {});
    }
  },
  created () {

  },
  mounted () {
    this.getUserInfo()
  }
}
</script>

<style scoped lang="scss">
  @import "~_style/mixin.scss";

  .userInfo {
    width: 360px;
    background: white;
    border-radius: 10px;

    > p {
      background-color: $colorGreen;
      display: inline-block;
      padding: 8px 16px;
      color: #fff;
      border-radius: 10px 0 10px 0;
    }

    .info {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;

      p {
        margin-top: 24px;
        font-size: 14px;

        &:nth-child(1) {
          font-weight: bold;
          font-size: 16px;
        }
      }
    }

    img {
      display: block;
      width: 92px;
      height: 92px;
      border-radius: 50%;
      border: 2px solid $colorGreen;
    }
  }
</style>
